package com.accp.crm.service;

import org.hibernate.SessionFactory;

import com.accp.crm.dao.CommonDAO;
import com.accp.crm.entity.PageBean;
import com.accp.crm.entity.Product;

public class ProductService implements IProductService {
     
	private CommonDAO<Product> productDAO;
	
	public void setSessionFactory(SessionFactory sessionFactory){
		productDAO=new CommonDAO<Product>(sessionFactory, Product.class);
	}
	
	public PageBean findByPage(int pageNo,String name,String type,String batch) {
		String hql="from Product p where 1=1";
		if (name!=null){
			hql += "and p.prodName like '%"
					+name+"%' ";
		}
		if (type!=null){
			hql += "and p.prodType like '%"
				+type+"%' ";
		}
		if (batch!=null){
			hql += "and p.prodBatch like '%"
				+batch+"%' ";
		}
		return this.productDAO.findByPage(hql,pageNo, 10);
	}
}
